package org.learn.intermediate.com.exercise;

import java.util.*;

public class GenericExercise {
    public static void main(String[] args) {
        HashSet<Student1> students = new HashSet<Student1>();
        students.add(new Student1("jack",15));
        students.add(new Student1("tom",17));
        students.add(new Student1("mary",18));
        
        //遍历
        for (Student1 student :students) {
            System.out.println(student);
        }
        HashMap<String, Student1> m = new HashMap<String, Student1>();
        m.put("no1",new Student1("jack",15));
        m.put("no2",new Student1("tom",17));
        m.put("no3",new Student1("mary",18));

        //迭代器
        Set<Map.Entry<String, Student1>> entries = m.entrySet();
        Iterator<Map.Entry<String, Student1>> iterator = entries.iterator();
        while (iterator.hasNext()) {
            Map.Entry<String, Student1> next =  iterator.next();
            System.out.println(next.getKey() + "-" + next.getValue());
        }
    }
}
class Student1{
    public String name;
    public int age ;

    public Student1(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student1{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
